package com.pengshun.modules.api.transport.controller;

import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.coal.validator.Third;
import com.pengshun.modules.api.transport.dto.TakeCarriageDto;
import com.pengshun.modules.api.transport.dto.TransportDto;
import com.pengshun.modules.api.transport.dto.TransportOrderDto;
import com.pengshun.modules.api.transport.dto.TransportSettDto;
import com.pengshun.modules.api.transport.service.TransportService;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @ClassName: TransportController
 * @Description:货运
 * @Author: lifei
 * @Date: 2020/11/16 3:18 下午
 * @Version: 1.0
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "商户货运管理")
@RequestMapping("/api/transport")
public class TransportController {

    private final TransportService transportService;

    @ApiOperation(value = "发布货运")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderAllotTransportId ", value = "货源订单id", dataType = "int",   paramType = "query"),


            @ApiImplicitParam(name = "shipDistrictAdcode", value = "发货人区code", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "shipLngx", value = "发货人经度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "shipLaty", value = "发货人纬度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "shipDetailAddress", value = "发货人详细地址", dataType = "string", required = true, paramType = "query"),

            @ApiImplicitParam(name = "receiveDistrictAdcode", value = "收货人区编码", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "receiveLngx", value = "收货人经度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "receiveLaty", value = "收货人纬度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "receiveDetailAddress", value = "收货人详细地址", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "shipName", value = "发货人姓名", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "shipPhone", value = "发货人电话", dataType = "string", required = true, paramType = "query"),

            @ApiImplicitParam(name = "name", value = "货物名(煤炭名)", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "receiveName", value = "收货人姓名", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "receivePhone", value = "收货人电话", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "freightPrice", value = "运输费(元/顿)", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "weight", value = "货物重量(顿)数量", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "mineMouthId", value = "矿口id(筛选用)", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "infoFee", value = "信息费(元/顿)", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "loadFee", value = "装车费(元/顿)", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "unloadFee", value = "卸车费(元/顿)", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "poundsFee", value = "磅费(元/顿)", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "otherFee", value = "其他费用", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "needCar", value = "需要车辆", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单id(可为空代表运输部自己发布)", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "isAppoint", value = "是否指定货运公司(默认0不指定、1指定)", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "备注", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "freightTypeName", value = "货运类型名字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "freightTypeCode", value = "货运类型编码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "freightTransportName", value = "货物类型名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "freightTransportCode", value = "货物类型编码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "vehicleTypeId", value = "车辆类型名字", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "vehicleTypeName", value = "车辆类型名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "vehicleLengthId", value = "车辆长度Id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "vehicleLengthName", value = "车辆长度名字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "joinMouthTime", value = "进矿预计排队时间(单位分钟)", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "loadCarTime", value = "装车预计排队时间(单位分钟)", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "lowWeight", value = "最低接取数量", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "运单有效开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "运单有效结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "oilProportion", value = "油卡比例", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "cashProportion", value = "现金比例", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "isContract", value = "是否承包0否1是", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "allowDiff", value = "允许差异吨位", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "shippingCompany", value = "发货单位", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "receiveCompany", value = "收货单位", dataType = "int", paramType = "query"),

            @ApiImplicitParam(name = "transportAssigns[0].userId", value = "指定运输公司id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "transportAssigns[0].merchantName", value = "指定运输公司id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "transportAssigns[1].userId", value = "指定运输公司id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "transportAssigns[1].merchantName", value = "指定运输公司id", dataType = "int", paramType = "query"),

            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/save", produces = "application/json; charset=utf-8")
    @Authorization
    @NoRepeatSubmit
    public BaseResult save(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Third.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        para.setCreateBy(user.getName());
        BaseResult res = transportService.save(para);
        return res;
    }

    @ApiOperation(value = "货运信息修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/update")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUpdateBy(user.getName());
        BaseResult res = transportService.update(para);
        return res;
    }

    @ApiOperation(value = "货运信息操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "id", value = "货运id ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "isShow", value = "0下架 1上架 ", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "1发布 5删除", dataType = "int", paramType = "query")
    })
    @PostMapping(value = "/update-status")
    @Authorization
    public BaseResult updateStatus(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUpdateBy(user.getName());
        BaseResult res = transportService.updateStatus(para);
        return res;
    }

    @ApiOperation(value = "货运信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/detil")
    @Authorization
    public BaseResult detil(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportService.detil(para);
        return res;
    }

    @ApiOperation(value = "商户货运信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态(0未发布，1已发布，2已完成", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/merchant-list")
    @Authorization
    public BaseResult merchantList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportService.list(para);
        return res;
    }

    @ApiOperation(value = "商户货运信息接单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0全部 1待装货、2已装货、3已卸货", dataType = "int", required = true, paramType = "query"),
    })
    @GetMapping(value = "/take-list")
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = TakeCarriageDto.class)
    })
    public BaseResult takeList(@ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        BaseResult res = transportService.selectTakeList(para);
        return res;
    }
    @ApiOperation(value = "商户货运信息结算列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0全部 1待结算2退回3已结算,4异常订单 ", dataType = "int",  paramType = "query"),
    })
    @GetMapping(value = "/sett-list")
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = TransportSettDto.class)
    })
    public BaseResult settList(@ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        BaseResult res = transportService.settList(para);
        return res;
    }


}
